<?
	 layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
	<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script
<div class="panel" style="height: 580px; overflow: auto;">
	<div class="panel-body pan" style="height: 580px; overflow: auto;">
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">产品名称
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="name" type="text" class="form-control" disabled="true" value=""  />
					</div>
				</div>
			</div>
		</div>
		<div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
			<label for="inputUsername" class="col-md-3 control-label">产品描述
			</label>
			<div class="col-md-12">
				<div class="input-icon">
					<textarea id="description" rows="2" disabled="true" cols="20" class="form-control"></textarea>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">计量类型
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="chargeType" disabled="true" class="form-control">
							<option value="">--请选择--</option>
							<option value="0">按产品库计费</option>
							<option value="1">固定单价计费</option>
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">产品价格
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="price" type="text" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">优惠/折扣金额
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="preferential" type="text" class="form-control" value="" placeholder="输入格式0.00" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">计量单位
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="units" class="form-control">
							<option value="">--请选择--</option>
							<option value="pian">篇</option>
							<!-- <option value="ye">页</option>
							<option value="zi">字</option> -->
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">优惠起始时间
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="preferentialDateStart" type="text" class="form-control" value="" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" />
					</div>
				</div>
			</div>
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">优惠终止时间
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="preferentialDateEnd" type="text" class="form-control" value="" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" />
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px;display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">封面图片</label>
				<div class="col-md-9">
					<div class="input-icon">
						<div style="display:inline " id="single"></div>
						<!-- <input type="button" class="btn btn-primary" onclick="upImages()" value="上传图片"  /> -->
						<textarea id="uploadImage" name="uploadImage"></textarea>
						<input id="coverImg" type="hidden" class="form-control" value="" />
					</div>
				</div>
			</div>
			<!-- <div class="col-lg-6"
				style="width: 400px; float:left; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">是否根据知识库同步更新产品数据
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="isSynchronous" class="form-control">
							<option value="0">不同步</option>
							<option value="1">同步</option>
						</select>
					</div>
				</div>
			</div> -->
		</div>
		<div class="row" style="margin-bottom: 10px;">
		<!-- 	<div class="col-lg-6"
				style="width: 400px; float:right; margin-right:20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">web页面链接地址
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="webUrl" type="text" class="form-control" value="" />
					</div>
				</div>
			</div> -->
		</div>
		<div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
			<label for="inputUsername" class="col-md-3 control-label">产品搜索表达式
			</label>
			<div class="col-md-12">
				<div class="input-icon">
					<textarea id="searchExpression" rows="2" disabled="true" cols="20"
						class="form-control"></textarea>
				</div>
			</div>
		</div>
		<!-- <div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
			<label for="inputUsername" class="col-md-3 control-label">solr索引库URL
			</label>
			<div class="col-md-12">
				<div class="input-icon">
					<textarea id="solrCoreUrl" rows="2" cols="20" class="form-control"></textarea>
				</div>
			</div>
		</div> -->

		<div id="showSeparator" style="margin-bottom: 30px;width: 750px;">
			<label for="inputUsername" class="col-md-3 control-label">知识库
			</label>
			<div id="classesName" class="row" style="margin-bottom: 10px;">

			</div>
		</div>
	</div>
</div>

<?} ?>
<script>
	var index1 = window.parent.getlay();
	var _editor;
	var classesIds = "";
	$(function() {
		if (index1 != 0) {
			$.ajax({
				type : "post",
				url : "./repositoryProductUpdate.do",
				data : {
					"id" : index1,
				},
				dataType : "json",
				async : false,
				success : function(data) {
					$("#name").val(data[0].name);
					$("#description").val(data[0].description);
					$("#price").val(data[0].price);
					$("#units").val(data[0].units);
					$("#status").val(data[0].status);
					$("#webUrl").val(data[0].webUrl);
					$("#classesIds").val(data[0].classesIds);
					classesIds = data[0].classesIds;
					$("#searchExpression").val(data[0].searchExpression);
				//	$("#isSynchronous").val(data[0].isSynchronous);
					$("#solrCoreUrl").val(data[0].solrCoreUrl);
					$("#coverImg").val(data[0].coverImg);
					$("#preferential").val(data[0].preferentialPrice);
					$("#preferentialDateStart").val(data[0].preferentialDateStart);
					$("#preferentialDateEnd").val(data[0].preferentialDateEnd);
					$("#chargeType").val(data[0].chargeType);
					$("#single").html("<img src='"+data[0].coverImg+"' width='30' height='30'/>");
					//selected("classesIds",data[0].classesIds);
					if(data[0].chargeType == '1'){
						document.getElementById('price').disabled = true;
				    	document.getElementById('preferential').disabled = true;
				    	document.getElementById('units').disabled = true;
				    	document.getElementById('preferentialDateStart').disabled = true;
				    	document.getElementById('preferentialDateEnd').disabled = true;
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
		$.ajax({
			type : "post",
			url : "./queryclasses.do",
			data : {},
			dataType : "json",
			async : false,
			success : function(data) {
				//alert(JSON.stringify(data));  
				$("#classesName").html("");
				var str = "";
				for ( var i = 0; i < data.length; i++) {
					str += "<div class='col-lg-1' style='width: 260px; float:left; margin-right:-20px;display:inline;'>";

					str += "<div class='col-md-9'>";
					str += "<div class='input-icon'>";
					str += "	<input type='checkbox' id='"+data[i].id+"' name='checkall' value="+data[i].id+" />&nbsp;&nbsp;";
					str +="	<label for='"+data[i].id+"' name='checkall'>"+data[i].nameZh;
					str += "</label></div>";
					str += "</div>";
					str += "</div>";
					//str+="<input type='checkbox' name='checkall' value="+data[i].id+" />"+data[i].nameZh+"";
				}
				$("#classesName").html(str);
				var classesids2 = classesIds.substring(0,
						classesIds.length - 1)
				var ids = classesids2.split(",");
				for ( var j = 0; j < ids.length; j++) {
					$("input[value=" + ids[j] + "]").attr("checked",
							true);
				}

			},
			error : function(data) {
				alert("请求失败");
			}
		});
		 _editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#coverImg").val(urlPath);
						$("#single").html("<a href="+urlPath+" download='w3logo'><img src='"+urlPath+"' width='30' height='30' /></a>");
	  	 			}
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	
		   	 });
	   }); 
	});
	//上传图片
	function upImages() {
		var myFiles = _editor.getDialog("insertimage");
	  		myFiles.open();
	   
	}
	function Page() {
		var value = [];
		$("input[name='checkall']:checked").each(function() {
			value.push($(this).val());
		});
		$.ajax({
			type : "post",
			url : "./Addproduct.do",
			data : {
				"id" : index1,
				"name" : $("#name").val(),
				"description" : $("#description").val(),
				"price" : $("#price").val(),
				"units" : $("#units").val(),
				"webUrl" : $("#webUrl").val(),
				"classesIds" : value,
				"searchExpression" : $("#searchExpression").val(),
				"isSynchronous" : 0,
				"solrCoreUrl" : $("#solrCoreUrl").val(),
				"coverImg" : $("#coverImg").val(),
				"status" : $("#status").val(),
				"preferential" : $("#preferential").val(),
				"chargeType" : $("#chargeType").val(),
				"preferentialDateStart" : $("#preferentialDateStart").val(),
				"preferentialDateEnd" : $("#preferentialDateEnd").val(),

			},
			dataType : "json",
			traditional : true,
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	//   默认单选函数
	function selected(selectname, selectid) {
		$("#" + selectname + " option").each(function() { //遍历全部option
			var v = $(this).val(); //获取option的内容
			if (v == selectid) {
				$(this).attr("selected", "selected");
			}
		});
	}
	//计费类型
	$(document).ready(function () { 
		  $("#chargeType").bind("change",function(){ 
		    if($(this).val()==1){
		    	document.getElementById('price').disabled = true;
		    	document.getElementById('preferential').disabled = true;
		    	$("#preferential").val("0.00");
		    	document.getElementById('units').disabled = true;
		    	document.getElementById('preferentialDateStart').disabled = true;
		    	document.getElementById('preferentialDateEnd').disabled = true;
		    }else{
		    	document.getElementById('price').disabled = false;
		    	document.getElementById('preferential').disabled = false;
		    	$("#preferential").val("");
		    	document.getElementById('units').disabled = false;
		    	document.getElementById('preferentialDateStart').disabled = false;
		    	document.getElementById('preferentialDateEnd').disabled = false;
		    } 
		  }); 
		});
</script>